﻿using EnglishAuction.BUS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EnglishAuction
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Error"] != null)
                {
                    lbThongBao.Text = Session["Error"].ToString();
                    Session["Error"] = null;
                }
                if (Session["CurrentUser"] != null)
                {
                    Response.Redirect("Default.aspx");
                }
            }
            else
            {

            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            string username = txtUsername.Text.Trim();
            string password = txtPassword.Text.Trim();
            NguoiDung nguoiDung = NguoiDungBUS.Login(username, Utilities.GetMD5Hash(password));
            if (nguoiDung != null)
            {
                Session["CurrentUser"] = nguoiDung;
                Response.Redirect("Default.aspx");
            }
            else
            {
                loginError.Visible = true;
                loginError.Text = "- Tài khoản hoặc mật khẩu không đúng.";
            }
        }
    }
}